<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vuex</title>
</head>
<body>
    <div id="app">
        <p>{{count}}</p>
        <button @click="increase">+</button>
        <button @click="increaseAsync">increaseAsync</button>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <script src="vuex.js"></script>
    <script>
        var store = new Vuex.Store({
            state:{count:1},
            mutations:{
                increase(state){
                    state.count++;
                }
            },
            actions:{
                increaseAsync(store){
                    setTimeout(()=>{
                        commit('increase');
                    },1000)
                }
            }
        })
        var vue  = new Vue({
            el:'#app',
            computed:{
                count(){
                    return store.state.count;
                }
            },
            methods:{
                increase(){
                    store.commit('increase');
                },
                increaseAsync(){
                    store.dispatch('increaseAsync');
                }
            }
        });
    </script>
</body>
</html>